package com.sskj.api.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sskj.api.domain.Manufacturer;
import com.sskj.api.service.IManufacturerService;
import com.sskj.api.vo.req.ManufacturerPageListReq;
import com.sskj.common.util.ApiResponseUtil;
import com.sskj.common.vo.ApiResponse;
import com.sskj.common.vo.SimplePagination;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Tag(name = "厂商模块")
@RestController
@RequestMapping("/admin/manufacturer")
@Validated
public class ManufacturerController {

    @Autowired
    private IManufacturerService manufacturerService;

    @Operation(summary = "新增厂商")
    @PostMapping("add")
    public ApiResponse<Object> add(@Valid @RequestBody Manufacturer manufacturer) {
        manufacturerService.add(manufacturer);

        return ApiResponseUtil.success();
    }

    @Operation(summary = "更新厂商")
    @PostMapping("update")
    public ApiResponse<Object> update(@Valid @RequestBody Manufacturer manufacturer) {
        manufacturerService.update(manufacturer);

        return ApiResponseUtil.success();
    }

    @Operation(summary = "厂商分页列表")
    @GetMapping("pageList")
    public ApiResponse<SimplePagination<Manufacturer>> pageList(ManufacturerPageListReq req) {
        IPage<Manufacturer> manufacturerIPage = manufacturerService.pageList(req);

        return ApiResponseUtil.success(manufacturerIPage);
    }
}
